<?php
namespace app\models;

use mvc\web\Model;

class Mobile extends Model
{
    public static function tableName()
    {
        return 'mobile';
    }

    public function rules()
    {
        return [
            'models' => [
                'required',
            ],
            'unique_number' => [
                'required',
                [
                    'string',
                    'max' => 100,
                ],
                'unique',
            ],
            'mobile_unique_number' => [
                'required',
                [
                    'string',
                    'max' => 100,
                ],
                'unique',
            ],
            'os' => [
                'required',
                'int'
            ],
        ];
    }

    public function labels()
    {
        return [
            'models' => '型号',
            'unique_number' => '自定义编码',
            'mobile_unique_number' => '手机唯一码',
            'os' => '操作系统',
        ];
    }

    public static function status($key = null)
    {
        $arr = [
            '1' => '未借',
            '2' => '已借'
        ];
        return $key !== null ? (isset($arr[$key]) ? $arr[$key] : '') : $arr;
    }

    public static function os($key = null)
    {
        $arr = [
            '1' => 'IOS',
            '2' => 'Android',
            '3' => 'Windows Phone'
        ];
        return $key !== null ? (isset($arr[$key]) ? $arr[$key] : '') : $arr;
    }
}